package com.zishi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zishi.model.vo.ReportVO;
import com.zishi.model.dto.ReportDTO;
import com.zishi.model.pojo.Report;
import com.zishi.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 报告表 前端控制器
 * </p>
 *
 * @author TP
 * @since 2022-05-05 08:53:41
 */
@RestController
@RequestMapping("/zishi/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 根据用户id获取其所有报告
     */
    @GetMapping("/{userId}")
    public List<ReportVO> getAllReportByUserId(@PathVariable Integer userId){
        return reportService.getAllReportByUserId(userId);
    }

    /**
     * 根据报告id获取报告
     */
    @GetMapping("/report/{id}")
    public ReportVO getReportById(@PathVariable Integer id) {
        return reportService.getReportById(id);
    }

    /**
     * 插入单个报告
     */
    @PostMapping("")
    public Integer insertReport(ReportDTO reportDTO) {
        return reportService.saveOneReport(reportDTO);
    }

    /**
     * 根据id删除报告
     */
    @DeleteMapping("/{id}")
    public boolean deleteReport(@PathVariable Integer id) {
        return reportService.removeById(id);
    }
}
